eratic / sites / blog / src / pages / [...slug].astro
204 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
/**
 * Every individual entry — posts and photo sets alike.
 *
 * A photo set gets its grid rendered from frontmatter before the body, so a
 * set with nothing but a caption still works; the MDX body is then whatever
 * story you want to tell around it. A post is just the body.
 */
import { render } from 'astro:content';
import Entry from '@eratic/core/layouts/Entry.astro';
import PhotoGrid from '@eratic/core/components/PhotoGrid.astro';
import Figure from '@eratic/core/components/Figure.astro';
import { mdxComponents } from '@eratic/core/components/mdx';
import { readingTime } from '@eratic/core';
import { allEntries, entryPath, entryKicker } from '../lib/entries';

export async function getStaticPaths() {
	const entries = await allEntries();
	return entries.map((entry) => ({
		params: { slug: entry.id },
		props: { entry },
	}));
}

const { entry } = Astro.props;
const { Content } = await render(entry);

const kicker =
	entry.kind === 'photos' ? entryKicker(entry) : readingTime(entry.body ?? entry.data.summary);
---

<Entry
	site="blog"
	title={entry.data.title}
	summary={entry.data.summary}
	path={entryPath(entry)}
	pubDate={entry.data.pubDate}
	updatedDate={entry.data.updatedDate}
	tags={entry.data.tags}
	canvas={entry.data.canvas}
	theme={entry.data.theme}
	image={entry.kind === 'photos' ? undefined : entry.data.cover?.src}
	kicker={kicker}
>
	{
		entry.kind === 'post' && entry.data.cover && entry.data.showCover && (
			<Figure
				src={entry.data.cover}
				alt={entry.data.coverAlt ?? entry.data.title}
				width="wide"
				priority
			/>
		)
	}

	{
		entry.kind === 'photos' && (
			<PhotoGrid
				photos={entry.data.photos}
				columns={entry.data.columns}
				exif={entry.data.exif}
				width="wide"
			/>
		)
	}

	<Content components={mdxComponents} />
</Entry>

static mirror of HEAD · about · clone: git clone https://git.makefuture.ro/eratic.git